<?php

class AdminLoginModel extends Model
{
	public function __construct()
	{
		parent::__construct();
		
		if (Input::request("action") != "login") return;
		
		$playerName = Input::request("name");
		$pass = Input::request("password");
		
		if (!preg_match(PATTERN_PLAYER_NAME, $playerName))
			$this->addError("name", "PLAYER_NAME_ERROR");
		
		if (!$this->hasError())
		{
			if ($playerName != ADMIN_LOGIN || $pass != ADMIN_PASSWORD)
				$this->addError("auth", "INVALID_LOGIN_PASSWORD");
			else
			{
				//Session::set("supervisor", true);
				//Session::remove("auth");
				$auth = Session::get("auth");
				if (is_null($auth))
					$auth = array();
				$auth["ac_level"] = Access::SUPEVISOR;
				Session::set("auth", $auth);
				if (Input::hasRequest("redirect"))
				{
					header("Location: /?action=login&view=" . Input::request("redirect"));
					die();
				}
				header("Location: /?view=admin&action=login");
				die();
			}
		}
	}
}

?>